home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1035.ASC < prev    next >
Encoding:
Text File  |  1992-10-23  |  12.9 KB  |  397 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1035
  9.   VERSION  :  3.1
  10.        OS  :  ALL
  11.      DATE  :  October 23, 1992                         PAGE  :  1/6
  12.  
  13.     TITLE  :  Using the Template version of the Class Library.
  14.  
  15.  
  16.  
  17.  
  18.  
  19.   This document provides an overview of the various causes of the
  20.   the "Illegal Structure Operation..." error message generated when
  21.   using template classes, template functions, and/or BIDS.
  22.  
  23.  
  24.   Consider the classic function template max():
  25.  
  26.          template <class T>
  27.          T max(T x, T y)
  28.          {
  29.             return (x > y) ? x : y ;
  30.          }
  31.  
  32.  
  33.   In order to pass in a user-defined type into this function, say
  34.   for instance class Foo{...};, Foo would need to have an
  35.   appropriate overloaded operator >() defined. If Foo did not have
  36.   such a function, passing in Foo objects would cause illegal or
  37.   undefined behavior because there is no comparison mechanism
  38.   for the compiler to use for Foo types. The same rules apply when
  39.   using the BIDS class library.
  40.  
  41.  
  42.   If you are using the template-based BIDS library, you'll see
  43.   advertised in the manuals that the template-based containers can
  44.   contain ANY type of object, default or user-defined, not just
  45.   those derived from the Object class (which is the requirement for
  46.   using the non-template base container classes).  This is true,
  47.   although there are requirements for user-defined types which are
  48.   not clearly defined in the documentation.  If these requirements
  49.   are not met, you will see compiler error messages such as "
  50.   Illegal structure operation in Base<T>::find<T> " or " Illegal
  51.   structure operation in Base<T>::findPred<T> ".
  52.  
  53.  
  54.   The following table illustrates what operators and functions need
  55.   to be provided for your type according to which BIDS container
  56.   you use.  For example, in order to store a user-defined class in
  57.   BI_BagAsVector<foo>, foo must have operator==( ) defined
  58.  
  59.  
  60.   ---------------------------------------------------------------- +
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1035
  75.   VERSION  :  3.1
  76.        OS  :  ALL
  77.      DATE  :  October 23, 1992                         PAGE  :  2/6
  78.  
  79.     TITLE  :  Using the Template version of the Class Library.
  80.  
  81.  
  82.  
  83.  
  84.                          |    |    |   |            |  Constructor |
  85.   BIDS                   | == | != | < | isSortable |Default| Copy |
  86.   -----------------------|----|----|---|------------|-------|------|
  87.   BI_VectorImp           |    |    |   |            |       |      |
  88.   -----------------------|----|----|---|------------|-------|------|
  89.   BI_CVectorImp          |    |    |   |            |       |      |
  90.   -----------------------|----|----|---|------------|-------|------|
  91.   BI_SVectorImp          | X  |    | X |            |  X    |   X  |
  92.   -----------------------|----|----|---|------------|-------|------|
  93.   BI_IVectorImp          |    |    |   |            |       |      |
  94.   -----------------------|----|----|---|------------|-------|------|
  95.   BI_ICVectorImp         | X  |    |   |      X     |       |      |
  96.   -----------------------|----|----|---|------------|-------|------|
  97.   BI_ISVectorImp         | X  |    | X |      X     |       |      |
  98.   -----------------------|----|----|---|------------|-------|------|
  99.                          |    |    |   |            |       |      |
  100.   -----------------------|----|----|---|------------|-------|------|
  101.   BI_ListImp             | X  |    |   |            |       |   X  |
  102.   -----------------------|----|----|---|------------|-------|------|
  103.   BI_SListImp            | X  |  X | X |            |   X   |   X  |
  104.   -----------------------|----|----|---|------------|-------|------|
  105.   BI_IListImp            | X  |    |   |            |       |      |
  106.   -----------------------|----|----|---|------------|-------|------|
  107.   BI_ISListImp           | X  |  X | X |            |   X   |   X  |
  108.   -----------------------|----|----|---|------------|-------|------|
  109.                          |    |    |   |            |       |      |
  110.   -----------------------|----|----|---|------------|-------|------|
  111.   BI_DoubleListImp       | X  |    |   |            |       |      |
  112.   -----------------------|----|----|---|------------|-------|------|
  113.   BI_SDoubleListImp      | X  |  X | X |            |   X   |   X  |
  114.   -----------------------|----|----|---|------------|-------|------|
  115.   BI_IDoubleListImp      | X  |    |   |            |       |      |
  116.   -----------------------|----|----|---|------------|-------|------|
  117.   BI_ISDoubleListImp     | X  |  X | X |            |   X   |   X  |
  118.   -----------------------|----|----|---|------------|-------|------|
  119.                          |    |    |   |            |       |      |
  120.   -----------------------|----|----|---|------------|-------|------|
  121.   BI_ArrayAsVectorImp    |    |    |   |            |   X   |   X  |
  122.   -----------------------|----|----|---|------------|-------|------|
  123.   BI_ArrayAsVector       | X  |    |   |            |   X   |   X  |
  124.   -----------------------|----|----|---|------------|-------|------|
  125.   BI_SArrayAsVector      | X  |    | X |      X     |   X   |   X  |
  126.   -----------------------|----|----|---|------------|-------|------|
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1035
  141.   VERSION  :  3.1
  142.        OS  :  ALL
  143.      DATE  :  October 23, 1992                         PAGE  :  3/6
  144.  
  145.     TITLE  :  Using the Template version of the Class Library.
  146.  
  147.  
  148.  
  149.  
  150.   BI_IArrayAsVector      | X  |    |   |      X     |       |      |
  151.   -----------------------|----|----|---|------------|-------|------|
  152.   BI_ISArrayAsVector     | X  |    | X |      X     |       |      |
  153.   -----------------------|----|----|---|------------|-------|------|
  154.                          |    |    |   |            |       |      |
  155.   -----------------------|----|----|---|------------|-------|------|
  156.   BI_StackAsVectorImp    |    |    |   |            |   X   |   X  |
  157.   -----------------------|----|----|---|------------|-------|------|
  158.   BI_StackAsVector       | X  |    |   |            |   X   |   X  |
  159.   -----------------------|----|----|---|------------|-------|------|
  160.   BI_IStackAsVector      | X  |    |   |            |   X   |      |
  161.   -----------------------|----|----|---|------------|-------|------|
  162.   BI_StackAsListImp      |    |    |   |            |   X   |   X  |
  163.   -----------------------|----|----|---|------------|-------|------|
  164.   BI_StackAsList         |    |    |   |            |   X   |   X  |
  165.   -----------------------|----|----|---|------------|-------|------|
  166.   BI_IStackAsList        | X  |    |   |            |   X   |      |
  167.   -----------------------|----|----|---|------------|-------|------|
  168.                          |    |    |   |            |       |      |
  169.   -----------------------|----|----|---|------------|-------|------|
  170.   BI_DequeAsVectorImp    |    |    |   |            |   X   |   X  |
  171.   -----------------------|----|----|---|------------|-------|------|
  172.   BI_DequeAsVector       |    |    |   |            |   X   |   X  |
  173.   -----------------------|----|----|---|------------|-------|------|
  174.   BI_IDequeAsVector      | X  |  X |   |            |   X   |      |
  175.   -----------------------|----|----|---|------------|-------|------|
  176.   BI_DequeAsDoubleListImp|    |    |   |            |   X   |   X  |
  177.   -----------------------|----|----|---|------------|-------|------|
  178.   BI_DequeAsDoubleList   | X  |  X |   |            |   X   |   X  |
  179.   -----------------------|----|----|---|------------|-------|------|
  180.   BI_IDequeAsDoubleList  |    |    |   |            |       |      |
  181.   -----------------------|----|----|---|------------|-------|------|
  182.                          |    |    |   |            |       |      |
  183.   -----------------------|----|----|---|------------|-------|------|
  184.   BI_QueueAsVector       |    |    |   |            |   X   |   X  |
  185.   -----------------------|----|----|---|------------|-------|------|
  186.   BI_IQueueAsVector      |    |    |   |            |       |      |
  187.   -----------------------|----|----|---|------------|-------|------|
  188.   BI_QueueAsDoubleList   | X  |  X |   |            |   X   |   X  |
  189.   -----------------------|----|----|---|------------|-------|------|
  190.   BI_IQueueAsDoubleList  |    |    |   |            |       |      |
  191.   -----------------------|----|----|---|------------|-------|------|
  192.                          |    |    |   |            |       |      |
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1035
  207.   VERSION  :  3.1
  208.        OS  :  ALL
  209.      DATE  :  October 23, 1992                         PAGE  :  4/6
  210.  
  211.     TITLE  :  Using the Template version of the Class Library.
  212.  
  213.  
  214.  
  215.  
  216.   -----------------------|----|----|---|------------|-------|------|
  217.   BI_BagAsVectorImp      |    |    |   |            |   X   |   X  |
  218.   -----------------------|----|----|---|------------|-------|------|
  219.   BI_BagAsVector         |    |    |   |            |   X   |   X  |
  220.   -----------------------|----|----|---|------------|-------|------|
  221.   BI_IBagAsVector        | X  |  X |   |      X     |       |      |
  222.   -----------------------|----|----|---|------------|-------|------|
  223.   BI_SetAsVector         | X  |    |   |            |   X   |   X  |
  224.   -----------------------|----|----|---|------------|-------|------|
  225.   BI_ISetAsVector        | X  | X  |   |      X     |       |      |
  226.   -----------------------------------------------------------------+
  227.  
  228.  
  229.   For any user-defined type that you put into the following
  230.   containers, an operator==( ) must be defined for your type in
  231.   order for the container to decide whether two objects are equal:
  232.  
  233.          BI_BagAsVector<T>
  234.          BI_BagAsVectorIterator<T>
  235.          BI_ArrayAsVector<T>
  236.          BI_SetAsVector<T>
  237.          BI_StackAsList<T>
  238.          BI_ListImp<T>
  239.  
  240.  
  241.   For any user-defined type that you put into the following
  242.   containers, you need to define operator !=() for the class for
  243.   comparison purposes, as well as link in BIDSx.LIB:
  244.  
  245.          BI_QueueAsDoubleList<T>
  246.          BI_DequeAsDoubleList<T>
  247.          BI_DoubleListImp<T>
  248.  
  249.  
  250.   For any type that you put into a sortable container (BI_S...), you
  251.   must define an operator<( ) as well for similar reasons.
  252.  
  253.  
  254.   NOTE: As of 6/4/92, this is only a partial list. Any added
  255.   information from programmers would be appreciated.  Please fax
  256.   comments/suggestions to 'C++ Technical Support  Attention DBA' at
  257.   (408)439-9100.  Thank you.
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                           NUMBER  :  1035
  273.   VERSION  :  3.1
  274.        OS  :  ALL
  275.      DATE  :  October 23, 1992                         PAGE  :  5/6
  276.  
  277.     TITLE  :  Using the Template version of the Class Library.
  278.  
  279.  
  280.  
  281.  
  282.   Here's an example Data class that implements ALL the necessary
  283.   overloaded operators to instantiate most BIDS classes (not all are
  284.   necessarily required in all cases):
  285.  
  286.   struct mydata
  287.   {
  288.       char* data;
  289.       int size;
  290.       mydata(int sz, char* s){ data = new char[sz]; strcpy(data,s);}
  291.       mydata(){data = new char[20];strcpy(data,"default");}
  292.       mydata(const mydata&);       //copy constructor
  293.      ~mydata(){delete data;}
  294.       mydata& operator=(const mydata&); //conversion operator
  295.       int operator==(const mydata&);
  296.       int operator<(const mydata&);
  297.       int operator>(const mydata&);
  298.       int operator!=(const mydata&);
  299.   };
  300.  
  301.   mydata& mydata::operator=(const mydata& a)
  302.   {
  303.           if (this!= &a)
  304.           {
  305.                   delete data;
  306.                   data = new char[size=a.size];
  307.                   strcpy(data,a.data);
  308.           }
  309.           return *this;
  310.   }
  311.  
  312.  
  313.   int mydata::operator==(const mydata& a)
  314.   {
  315.           if (strcmp(data,a.data) == 0)
  316.               return 1;
  317.           else
  318.               return 0;
  319.   }
  320.  
  321.  
  322.   int mydata::operator!=(const mydata& a)
  323.   {
  324.           if (strcmp(data,a.data) != 0)
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland C++                           NUMBER  :  1035
  339.   VERSION  :  3.1
  340.        OS  :  ALL
  341.      DATE  :  October 23, 1992                         PAGE  :  6/6
  342.  
  343.     TITLE  :  Using the Template version of the Class Library.
  344.  
  345.  
  346.  
  347.  
  348.               return 1;
  349.           else
  350.               return 0;
  351.   }
  352.  
  353.  
  354.   int mydata::operator<(const mydata& a)
  355.   {
  356.           if(strcmp(data,a.data) < 0)
  357.             return 1;
  358.           else
  359.             return 0;
  360.   }
  361.  
  362.  
  363.   int mydata::operator>(const mydata& a)
  364.   {
  365.           if(strcmp(data,a.data) > 0)
  366.             return 1;
  367.           else
  368.             return 0;
  369.   }
  370.  
  371.  
  372.   mydata::mydata(const mydata& a)
  373.   {
  374.           data = new char[size=a.size];
  375.           strcpy(data,a.data);
  376.   }
  377.  
  378.  
  379.  
  380.  
  381.   DISCLAIMER: You have the right to use this technical information
  382.   subject to the terms of the No-Nonsense License Statement that you
  383.   received with the Borland product to which this information
  384.   pertains.
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.